<?php 
namespace app\mall\model;
use think\Model;
class StoreChengpinOrderr extends Model{
	protected $pk = 'id';
	protected $table = 'ys_store_chengpin_orderr';
    protected $field = true;        //自动忽略不存在的字段
    /**
     * 处理发货方法
     * @return [type] [description]
     */
    /**
     * 更新申请详情记录表
     * @return [type] [description]
     */
    private function update_order($da){
    	$del_num = $da['del_num'];		//发货数量
    	$d_id = $da['id'];              //详情记录ID
        $stock = $da['stock'];
        $name  =$da['name'];
    	foreach($del_num as $k => $v){
            if($v>$stock[$k]) return $name[$k]."库存不足，请重填！";
    		$data[$k]['del_num'] = $v;
    		$data[$k]['id'] = $d_id[$k];
    		$data[$k]['status'] = 1;
    		$data[$k]['deal_time'] = time();
    	}
    	return $data;
    }	
    /**
     * 保存订单详情记录表
     * @return [type] [description]
     */
    public function save_order($data){
    	$da = $this->update_order($data);		//处理数
        if(!is_array($da)) return ['code'=>0,'msg'=>$da];
    	$result = $this->saveall($da);			//保存所有数据
    	if($result!==false){
    		return ['code'=>1,'msg'=>'保存成功'];
    	}else{
    		return ['code'=>0,'msg'=>'保存失败'];
    	}
    }
    /**
     * 驳回申请
     * @return [type] [description]
     */
    public function rebut($data){
        $da = array();
        foreach($data as $k => $v){
            $da[$k]['id'] = $v['id'];
            $da[$k]['deal_time'] = time();
            $da[$k]['status'] = 2;
        }
        $result = $this->saveall($da);          //保存所有数据
        if($result!==false){
            return ['code'=>1,'msg'=>'驳回成功'];
        }else{
            return ['code'=>0,'msg'=>'驳回失败'];
        }
    }


}
?>